﻿using System;
using System.Collections.Generic;
using System.Text;

namespace GGSharp.Radio
{
    public class LoginResponse : RDSResponseBase
    {
        private int _read1Length;
        private int _read2Length;
        private int _read1Start;
        private int _read2Start;
        private string _authServer;
        private string _channelList;

        public LoginResponse(RequestInfo request)
        {
            this.Request = request;
            this.Type = ResponseType.Login;
        }

        public string AuthorizationServer
        {
            get { return _authServer; }
            protected set
            {
                _authServer = value;
                OnPropertyChanged("AuthorizationServer");
            }
        }

        public string ChannelListAddress
        {
            get { return _channelList != null ? _channelList + ".xml" : null; }
            protected set
            {
                _channelList = value;
                OnPropertyChanged("ChannelListAddress");
            }
        }

        public override void Read(string response)
        {
            //1;1;1;1;1;600;Trwa logowanie do GaduRadio...;https://gr-grr-15.gaduradio.pl:443/auth.gg;http://static.gaduradio.pl:80/stations/2008070201;;
            string[] values = response.Split(';');
            Int32.TryParse(values[1], out _read1Start);
            Int32.TryParse(values[2], out _read1Length);
            Int32.TryParse(values[3], out _read2Start);
            Int32.TryParse(values[4], out _read2Length);
            this.RDSText = values[6];
            this.AuthorizationServer = values[7];
            this.ChannelListAddress = values[8];
        }
    }
}
